package com.skytech.component.monitor.task;

import com.skytech.component.monitor.enterprise_data_monitoring.JiangSuService;
import com.skytech.component.monitor.enterprise_data_monitoring.PM25Service;
import com.skytech.component.monitor.enterprise_data_monitoring.WaterPollutionService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.Async;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Service;

import java.text.SimpleDateFormat;
import java.util.Date;

@Service
@Async
public class ScheduledTask {
    @Autowired
    private JiangSuService jiangSuService;

    @Autowired
    private PM25Service pm25Service;

    @Autowired
    private WaterPollutionService waterPollutionService;
   Boolean use=false;
   Boolean usePM25=false;
   Boolean useWater=false;

    private static final Logger log = LoggerFactory.getLogger(ScheduledTask.class);
    @Scheduled(cron = "0 00 01 ? * *")
    public void startJiangsu(){
        log.debug("江苏定时任务开始");
        if(!use) {
            use=true;
            jiangSuService.start();
            use=false;
        }else {
            log.debug("上一个任务未完成");
        }
    }

    @Scheduled(cron = "0 00 0/1 ? * *")
    public void startPM25(){
        log.debug("PM2.5定时任务开始");
        if(!usePM25) {
            usePM25=true;
            pm25Service.start();
            usePM25=false;
        }else{
            log.debug("上一个任务未完成");
        }
    }

    @Scheduled(cron = "0 00 0/1 ? * *")
    public void startWaterPollution(){
        log.debug("水污染定时任务开始");
        if(!useWater) {
            useWater=true;
            waterPollutionService.start();
            useWater=false;
        }else{
            log.debug("上一个任务未完成");
        }
    }

}
